/**
 * 动态加载JS文件,不支持跨域加载
 */

DynamicLoadJS = function(url, id) {
	var _xmlHttp;
	var fileName = "";

	if (url.endWith('.js')) {
		var index = url.lastIndexOf("/");
		if (index == -1) {
			fileName = url;
		} else {
			fileName = url.substring(index + 1);
		}
	} else {
		throw new Error("加载文件类型错误.");
	}

	var GetXmlHttpRequest = function() {
		if (window.XMLHttpRequest) {
			_xmlHttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			_xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}

		if (_xmlHttp == null) {
			throw new Error("浏览器不支持XmlHttpRequest.");
		}
	}();

	var IncludeJS = function(id, source) {
		if (!document.getElementById(id) && source != null) {
			var head = document.getElementsByTagName("HEAD").item(0);

			var script = document.createElement("script");
			script.language = "javascript";
			script.type = "text/javascript";
			script.id = id;
			script.defer = true;
			script.text = source;

			head.appendChild(script);
		} else {
			throw new Error("加载'"+jsFileName+"'文件失败.");
		}
	};

	_xmlHttp.onReadyStateChange = function() {
		if (_xmlHttp.readyState == 4) {
			if (_xmlHttp.status == 200 || _xmlHttp.status == 304) {
				alert(_xmlHttp.responseText);
				IncludeJS(id, _xmlHttp.responseText);
			}
		}
	}

	_xmlHttp.open("GET", url, false);
	_xmlHttp.send(null);
}

/**
 * 对Javascript中的endWith方法的扩展
 */
 
String.prototype.endWith = function(str) {
	if (!str || str.length == 0 || str.length > this.length)
		return false;

	if (this.substring(this.length - str.length) == str)
		return true
	else
		return false;
};

/**
 * 对Javascript中的startWith方法的扩展
 */

String.prototype.startWith = function(str) {
	if (!str || str.length == 0 || str.length > this.length)
		return false;

	if (this.substring(0, str.length) == str)
		return true;
	else
		return false;
};